<?php
namespace app\index\service;

use app\index\model\ContractCaiModel;
use app\index\model\ContractShiModel;
use app\index\model\DealcomModel;
use app\index\model\DeptModel;
use app\index\model\EnginModel;
use app\index\model\FlowClassModel;
use app\index\model\FlowCourseModel;
use app\index\model\FlowSetModel;
use app\index\model\MenuButModel;
use app\index\model\MenuModel;
use app\index\model\UserGangModel;
use app\index\model\UserRoleModel;
use think\Db;

class MenuService extends CommonService
{

    public function user_menu($pid=0){
        $whereTeshu = "";
        if($this->userinfo['token_roletype'] == 1 && in_array(25, explode(',', $this->userinfo['roleid']))){
            $whereTeshu = "id not in (54,174,56,224)";
        }
        $where[] = ['status','eq',1];
        $where[] = ['ispc','eq',1];
        $whereRole = '';
        if($this->userinfo['issuper'] < 1){
            $userMenuStr = $this->get_user_authmenu();
            $userMenuStr = empty($userMenuStr) ? '0' : $userMenuStr;
            $whereRole = "isrole = 0 or (isrole = 1 and id in (".$userMenuStr."))";
        }

        $data = MenuModel::where($where)->where($whereRole)->where($whereTeshu)->where(['pid'=>$pid])->order('sort ASC')->select()->toArray();
        if($pid > 0){
            foreach ($data as &$item){
                $item['children'] = MenuModel::where($where)->where($whereRole)->where($whereTeshu)->where(['pid'=>$item['id']])->order('sort ASC')->select()->toArray();
            }
        }

        return $data;
    }

    public function user_menu_mob(){
        $where[] = ['status','eq',1];
        $where[] = ['ismob','eq',1];
        $whereRole = '';
        if($this->userinfo['issuper'] < 1){
            $userMenuStr = $this->get_user_authmenu();
            $whereRole = "isrole = 0 or (isrole = 1 and id in (".$userMenuStr."))";
        }

        $data = MenuModel::where($where)->where($whereRole)->where(['pid'=>0])->order('sort ASC')->select()->toArray();
        foreach ($data as &$item){
            $item['children'] = MenuModel::where($where)->where($whereRole)->where(['pid'=>$item['id']])->order('sort ASC')->select()->toArray();
            foreach ($item['children'] as &$item2){
                $item2['children'] = MenuModel::where($where)->where($whereRole)->where(['pid'=>$item2['id']])->order('sort ASC')->select()->toArray();
            }
        }

        return $data;
    }

    private function get_user_authmenu(){
        $data = [];
        $role = UserRoleModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'type'=>$this->userinfo['token_roletype']])
            ->where('id','in', $this->userinfo['roleid'])->column('menu');
        foreach ($role as $itemMenu){
            if($itemMenu){
                $data = array_unique(array_merge($data, explode(',', $itemMenu)));
            }
        }
        return implode(',',$data);
    }

    private function get_user_authbut(){
        $data = [];
        $role = UserRoleModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'type'=>$this->userinfo['token_roletype']])
            ->where('id','in', $this->userinfo['roleid'])->column('but');
        foreach ($role as $itemBut){
            $data = array_unique(array_merge($data, explode(',', $itemBut)));
        }
        return $data;
    }


    public function get_butauth($modedir='', $super=0){
        $data = MenuButModel::where(['modedir'=>$modedir,'status'=>1])->order('sort ASC')->select()->toArray();

        if($super < 1){
            $super = $this->userinfo['issuper'];
        }

        $list = [];
        $userButArr = (new MenuService())->get_user_authbut();
        foreach ($data as $v){
            if($super < 1){
                if(!in_array($v['id'], $userButArr)){
                    continue;
                }
            }
            if($v['butname'] == 'add'){
                if($modedir == 'enginlian'){
                    $modedir = 'engin';
                }
                if($modedir == 'cert_use_bid'){
                    $modedir = 'cert_use';
                }
                $set = FlowSetModel::where(['modenum'=>$modedir])->find();
                if($set){
                    $class = FlowClassModel::where(['comid'=>$this->userinfo['comid'],'setid'=>$set['id'],'status'=>1])->find();
                    if($class){
                        $course = FlowCourseModel::where(['comid'=>$this->userinfo['comid'],'status'=>1,'classid'=>$class['id'],'deleted_user'=>0])->find();
                        if($course){
                            $v['butname'] = 'add_flow';
                        }
                    }
                }
            }
            $list[] = $v;
        }

        return $list;
    }

    public function check_flow_start_users($users=''){
//        if(!$users){
//            return true;
//        }
//        if(in_array('user'.$this->userinfo['id'], explode(',', $users))){
//            return true;
//        }
//        if(in_array('dept'.$this->userinfo['deptid'], explode(',', $users))){
//            return true;
//        }
//        return false;
    }


    public function get_miss_where($modedir, $alias=''){

        $str = '';
        $alias = empty($alias) ? '' : $alias.'.';

        if($this->userinfo['issuper'] > 0){
            return '';
        }

        $menuInfo = MenuModel::where(['modedir'=>$modedir])->find();
        if(!$menuInfo && !$menuInfo['id']){
            return $alias."id < 0";
        }

        if($this->userinfo['token_roletype'] == 1){
            //全部权限
        }

        if($this->userinfo['token_roletype'] == 2){
            $enginArr = (new EnginService())->get_user_engin();
            $enginArrStr = implode(',', $enginArr);
            if($enginArrStr){
                $enginStr = '('.$enginArrStr.')';
            }else{
                $enginStr = '(0)';
            }

            if($menuInfo['modedir'] == 'homeengin'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'enginlian'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'cert_use_engin_count'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'contract_shi_tai'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'contract_cai_tai'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'contract_shi'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'contract_cai'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'contract_tai'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_budget'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'tong_cheng_suan'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'tong_cheng_xiang'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'tong_cheng_cheng'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'tong_cheng_rcj'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'tong_cheng_cai'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'tong_cheng_guan'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'payment_engin'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'income_engin_kuan'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'contract_nei'){
                $neiidarr = ContractShiModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1])
                    ->where('status','in',[0,1])->where('enginid','in',$enginArr)->column('neiid');
                $neiidarrStr = implode(',', $neiidarr);
                if($neiidarrStr){
                    $neiidStr = '('.$enginArrStr.')';
                }else{
                    $neiidStr = '(0)';
                }
                $str = $alias.'id in '.$neiidStr;
            }
            if($menuInfo['modedir'] == 'payment_neikou'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'payment_neifu'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_bond_jiao'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_bond_kai'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'stuff_cai'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'stuff_ru'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'stuff_chu'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'stuff_tui'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'stuff_jie'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'stuff_mingxi'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'stuff_ku'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'labour_shen'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'labour_ling'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'labour_jie'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'labour_xiang'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'labour_yong'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'labour_hua'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'labour_wage'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'device_jin'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'device_mingxi'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'device_jie'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'device_lin'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'subbao_shen'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'subbao_jie'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_xun'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_zheng'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'speed_zong'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'speed_month'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_diary'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_speed'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'visa'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'speed_jingen'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'speed_jinhui'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'speed_yuechan'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_chan'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_junyan'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_junjie'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_elecfile'){
                //根据项目导航权限来，不做处理
            }
            if($menuInfo['modedir'] == 'engin_fold'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_stamp'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_stamp_detail'){
                $str = $alias.'enginid in '.$enginStr;
            }
        }

        if($this->userinfo['token_roletype'] == 3){
            $lianerarr = DealcomModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
                ->where('id','in',$this->userinfo['lianer'])->column('name');
            $enginArr = EnginModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'status'=>1,'isturn'=>1,'business'=>2])
                ->where('lian_unit','in',$lianerarr)->column('id');
            $enginArrStr = implode(',', $enginArr);
            if($enginArrStr){
                $enginStr = '('.$enginArrStr.')';
            }else{
                $enginStr = '(0)';
            }

            if($menuInfo['modedir'] == 'homeengin'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'enginlian'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'contract_shi'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'contract_cai'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'contract_tai'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_budget'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'tong_cheng_suan'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'tong_cheng_xiang'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'tong_cheng_cheng'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'tong_cheng_rcj'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'tong_cheng_cai'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'tong_cheng_guan'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'payment_engin'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'income_engin_kuan'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'contract_nei'){
                $neiidarr = ContractShiModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1])
                    ->where('status','in',[0,1])->where('enginid','in',$enginArr)->column('neiid');
                $neiidarrStr = implode(',', $neiidarr);
                if($neiidarrStr){
                    $neiidStr = '('.$enginArrStr.')';
                }else{
                    $neiidStr = '(0)';
                }
                $str = $alias.'id in '.$neiidStr;
            }
            if($menuInfo['modedir'] == 'payment_neikou'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'payment_neifu'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_bond_jiao'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_bond_kai'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'stuff_cai'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'stuff_ru'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'stuff_jie'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'stuff_mingxi'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'stuff_ku'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'labour_shen'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'labour_ling'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'labour_jie'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'labour_xiang'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'labour_yong'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'device_jin'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'device_mingxi'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'device_jie'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'device_lin'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'subbao_shen'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'subbao_jie'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_xun'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_zheng'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_diary'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'speed_zong'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'speed_month'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_speed'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'visa'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'speed_jingen'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'speed_jinhui'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'speed_yuechan'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_chan'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_junjie'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_junyan'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_elecfile'){
                //根据项目导航权限来，不做处理
            }
            if($menuInfo['modedir'] == 'engin_fold'){
                $str = $alias.'id in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_stamp'){
                $str = $alias.'enginid in '.$enginStr;
            }
            if($menuInfo['modedir'] == 'engin_stamp_detail'){
                $str = $alias.'enginid in '.$enginStr;
            }
        }

        if($this->userinfo['token_roletype'] == 4){
            $gongerarr = DealcomModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
                ->where('id','in',$this->userinfo['gonger'])->column('name');
            $gongerStr = '';
            foreach ($gongerarr as $v){
                if(empty($gongerStr)){
                    $gongerStr .= "'".$v."'";
                }else{
                    $gongerStr .= ",'".$v."'";
                }
            }
            if($gongerStr){
                $gongerStr = "(".$gongerStr.")";
            }else{
                $gongerStr = "('!@#$%jhgL')";
            }

            if($menuInfo['modedir'] == 'contract_cai'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'payment_engin'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'stuff_ru'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'stuff_mingxi'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'stuff_jie'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'device_jin'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'device_mingxi'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'device_jie'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'device_lin'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'labour_shen'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'labour_jie'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'labour_ling'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'subbao_shen'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'subbao_jie'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'piao_shou_hui'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'stuff_cai'){
                $str = $alias.'gonger in '.$gongerStr;
            }
            if($menuInfo['modedir'] == 'labour_yong'){
                $str = $alias.'gonger in '.$gongerStr;
            }
        }

//        if($this->userinfo['token_roletype'] == 5){
//            $subchanid = $this->get_chan_subid((new UserService())->get_user_chanid(), 2);
//            $str = $alias.'chanid in ('.$subchanid.')';
//        }

        if($this->userinfo['token_roletype'] == 5){
            $userChanid = (new UserService())->get_user_chanid();


            if($menuInfo['modedir'] == 'engin'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'enginlian'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_use_engin_count'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'contract_shi'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'contract_cai'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'contract_shi_tai'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'contract_cai_tai'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'contract_tai'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_budget'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_suan'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_xiang'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_cheng'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_rcj'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_cai'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_guan'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_engin'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'income_engin_kuan'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'contract_nei'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_neikou'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_neifu'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_bond_jiao'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_bond_kai'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'stuff_cai'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'stuff_ru'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'stuff_chu'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'stuff_tui'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'stuff_jie'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'stuff_mingxi'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'stuff_ku'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'labour_shen'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'labour_ling'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'labour_jie'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'labour_ban'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'labour_gong'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'labour_xiang'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'labour_yong'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'labour_hua'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'labour_wage'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'device_jin'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'device_mingxi'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'device_jie'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'device_lin'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'subbao_shen'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'subbao_jie'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_xun'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_zheng'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_jian'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'speed_zong'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'speed_month'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_diary'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_speed'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'visa'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'speed_jingen'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'speed_jinhui'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'speed_yuechan'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_chan'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_junyan'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_junjie'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_elecfile'){
                //根据左侧导航判断权限  此处不需要设置
            }
            if($menuInfo['modedir'] == 'engin_fold'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_stamp'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_stamp_detail'){
                $str = 'e.chanid = '.$userChanid;
            }


            //==============投标==============
            if($menuInfo['modedir'] == 'bid_pool'){
                $str = 'bid.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'bid_customer'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'bid'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'bid_jindu'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'bid_win'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'bid_grant_book'){
                $str = 'b.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_use_bid_count'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'bid_book'){
                $str = 'b.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'bid_book_count'){
                $str = 'b.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'bid_bond'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'bid_bond_jiao'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'bid_bond_kai'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'bid_sum'){
                $str = 'bid.chanid = '.$userChanid;
            }



            //==============财务==============
            if($menuInfo['modedir'] == 'income_engin'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'income_qi'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'income_engin_dai'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'income_ying'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'income_incshou'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_engin_kuan'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_neifu_kuan'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_day'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_bao'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_gong'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_paydata'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_paybao'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'contract_kuan'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_jie'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'income_huan'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_jie_tai'){
                $str = 'jie.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'payment_jie_hui'){
                $str = 'jie.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_bond_jiao_kuan'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_bond_shou'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_bond_fan'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'engin_bond_kai_cai'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'piao_kai'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'piao_shou'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'piao_kai_hui'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'piao_shou_hui'){
                $str = 'shou.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'piao_tax'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'piao_engin_hui'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'dealcom'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'account'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'account_shou'){
                $str = 'acc.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'account_zhi'){
                $str = 'acc.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'account_diao'){
                $str = $alias.'chanid = '.$userChanid;
            }

            //==============证书==============
            if($menuInfo['modedir'] == 'cert'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_out'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_expire_expiry'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_expire_electron'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_expire_inspect'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'achieve'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_company'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_company_expire'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_employ'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_employ_count'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_use_bid'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_use'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_borrow'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_borrow_yuan'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_borrow_dian'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_form'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_census'){
                $str = $alias.'chanid = '.$userChanid;
            }


            //==============行政==============
            if($menuInfo['modedir'] == 'notice'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'wen_ban'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'wen_fa'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'wen_shou'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'wen_fen'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'wu_cai'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'wu_ru'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'wu_guan'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'wu_ling'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'asset'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'meet'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'seal'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'seal_gai'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'seal_gai_detail'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'dang'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'dang_jie'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'dang_jie_detail'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'news'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'huiall'){
                $str = $alias.'chanid = '.$userChanid;
            }


            //==============人事==============
            if($menuInfo['modedir'] == 'cert_person'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'archive_tong'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_perru'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_person_leave'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'cert_zhao'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'kao_jia'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'kao_chu'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'kao_ban'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'kao_chai'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'wage'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'archive_diao'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'archive_zhuan'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'archive_out'){
                $str = $alias.'chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'archive_jiao'){
                $str = $alias.'chanid = '.$userChanid;
            }


            //==============报表==============
            if($menuInfo['modedir'] == 'tong_jing_zi'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_jing_lian'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_jing_dong'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_jing_bian'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_zi_jing'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_zi_xiang'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_zi_dan'){
                $str = 'd.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_zi_xian'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_zi_dian'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_zi_zhi'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_zi_bao'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_suan'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_xiang'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_cheng'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_rcj'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_cai'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_guan'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_cheng_zeng'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_chan_jin'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_chan_yue'){
                $str = 'e.chanid = '.$userChanid;
            }
            if($menuInfo['modedir'] == 'tong_gong_xiang'){
                $str = 'e.chanid = '.$userChanid;
            }
        }

        return $str;
    }


    public function get_opt_where($modedir, $alias=''){
        $str = '';
        $alias = empty($alias) ? '' : $alias.'.';

        if($this->userinfo['issuper'] > 0){
            return '';
        }


        if($this->userinfo['token_roletype'] == 1){
            //全部权限
        }

        if($this->userinfo['token_roletype'] == 2){
            $enginArr = (new EnginService())->get_user_engin();
            $enginArrStr = implode(',', $enginArr);
            if($enginArrStr){
                $enginStr = '('.$enginArrStr.')';
            }else{
                $enginStr = '(0)';
            }


            if($modedir == 'engin'){
                $str = $alias.'id in '.$enginStr;
            }

            $bidArr = (new BidService())->get_user_bid();
            $bidArrStr = implode(',', $bidArr);
            if($bidArrStr){
                $bidStr = '('.$bidArrStr.')';
            }else{
                $bidStr = '(0)';
            }

            if($modedir == 'bid'){
                $str = $alias.'id in '.$bidStr;
            }

        }

        if($this->userinfo['token_roletype'] == 3){
            $lianerarr = DealcomModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
                ->where('id','in',$this->userinfo['lianer'])->column('name');
            $lianerStr = '';
            foreach ($lianerarr as $v){
                if(empty($lianerStr)){
                    $lianerStr .= "'".$v."'";
                }else{
                    $lianerStr .= ",'".$v."'";
                }
            }
            $lianerStr = "(".$lianerStr.")";

            $enginArr = EnginModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1,'business'=>2])
                ->where('lian_unit','in',$lianerarr)->column('id');
            $enginStr = '('.implode(',', $enginArr).')';

            if($modedir == 'engin'){
                $str = $alias.'lian_unit in '.$lianerStr;
            }

            $bidArr = (new BidService())->get_user_bid();
            $bidArrStr = implode(',', $bidArr);
            if($bidArrStr){
                $bidStr = '('.$bidArrStr.')';
            }else{
                $bidStr = '(0)';
            }

            if($modedir == 'bid'){
                $str = $alias.'id in '.$bidStr;
            }

        }

        if($this->userinfo['token_roletype'] == 4){
            $gongerarr = DealcomModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
                ->where('id','in',$this->userinfo['gonger'])->column('name');
            $gongerStr = '';
            foreach ($gongerarr as $v){
                if(empty($gongerStr)){
                    $gongerStr .= "'".$v."'";
                }else{
                    $gongerStr .= ",'".$v."'";
                }
            }
            $gongerStr = "(".$gongerStr.")";


            if($modedir == 'engin'){
                $enginArr = ContractCaiModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'isturn'=>1,'status'=>1])
                    ->where('gonger','in',$gongerStr)->column('enginid');
                $str = $alias.'id in '.$enginArr;
            }

            $bidArr = (new BidService())->get_user_bid();
            $bidArrStr = implode(',', $bidArr);
            if($bidArrStr){
                $bidStr = '('.$bidArrStr.')';
            }else{
                $bidStr = '(0)';
            }

            if($modedir == 'bid'){
                $str = $alias.'id in '.$bidStr;
            }

        }

        if($this->userinfo['token_roletype'] == 5){
            $subchanid = $this->get_chan_subid((new UserService())->get_user_chanid(), 2);
            $str = $alias.'chanid in ('.$subchanid.')';
        }

        return $str;
    }



    public function get_user_authinfo($menuid){
        $data = [];
        $role = UserRoleModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0,'type'=>$this->userinfo['token_roletype']])
            ->where('id','in', $this->userinfo['roleid'])->column('auth');

        foreach ($role as $itemAuth){
            $auth = json_decode($itemAuth, true);
            if(is_array($auth) && isset($auth[$menuid])){
                $data[] = $auth[$menuid];
            }
        }
        return array_unique($data);
    }

    public function get_dept_subid($id=0, &$idArr=[]){
        if(!$id){
            return [];
        }
        $idArr[] = $id;
        $data = DeptModel::where(['comid'=>$this->userinfo['comid'],'pid'=>$id,'deleted_user'=>0])->column('id');
        foreach ($data as $deptid){
            $this->get_dept_subid($deptid, $idArr);
        }
        return implode(',', $idArr);
    }

    public function get_chan_subid($id=0, $type, &$idArr=[]){
        if(!$id){
            return [];
        }
        if($type == 2){
            $idArr[] = $id;
        }
        $data = DeptModel::field('id,type')->where(['comid'=>$this->userinfo['comid'],'pid'=>$id,'deleted_user'=>0])->select()->toArray();
        foreach ($data as $v){
            $this->get_chan_subid($v['id'], $v['type'], $idArr);
        }
        return implode(',', $idArr);
    }

    public function get_chanid_sons($id){
        $list = [(int)$id];
        $seaarr = [$id];

        while (count($seaarr) > 0) {
            $son = DeptModel::where(['comid'=>$this->userinfo['comid'],'deleted_user'=>0])
                ->where('pid','in',$seaarr)->column('id');
            $seaarr = [];
            foreach ($son as $v){
                $list[] = $v;
                $seaarr[] = $v;
            }
        }
        return $list;
    }
}
